﻿using Autofac;
using Autofac.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using SBlogCore.Common.AutofacExtend.Modules;

namespace SBlogCore.Common.AutofacExtend
{
    [SkipScan]
    public static class Extensions
    {
        /// <summary>
        /// AutoFac批量注入
        /// </summary>
        /// <param name="hostBuilder"></param>
        /// <returns></returns>
        public static IHostBuilder AutofacRegister(this IHostBuilder hostBuilder)
        {
            //用来重写原有的依赖注入工厂
            hostBuilder.UseServiceProviderFactory(new AutofacServiceProviderFactory());
            hostBuilder.ConfigureContainer<ContainerBuilder>((context, builder) =>
            {
                builder.RegisterModule<AutofacModuleRegister>();
            });
            return hostBuilder;
        }
    }
}
